package com.gw.vip.center.controller;

import com.gw.vip.center.auth.CheckToken;
import com.gw.vip.center.dto.AuthCodeDto;
import com.gw.vip.center.dto.RandomCodeDto;
import com.gw.vip.center.dto.UserInfoByCodeDto;
import com.gw.vip.center.sign.RequiredSign;
import com.gw.vip.center.vo.AuthCodeVo;
import com.gw.vip.center.vo.RandomCodeVo;
import com.gw.vip.center.vo.UserInfoByCodeVo;
import com.gw.vip.center.zib.AuthBiz;
import com.gw.vip.common.log.PrintlnLog;
import com.gw.vip.common.vo.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author GW
 * @description
 * @since 2022-04-17
 */
@RestController
@RequestMapping("auth")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AuthController {

    private final AuthBiz authBiz;

    @PrintlnLog(description = "获取验证码")
    @PostMapping("mailAuthCode")
    public Result mailAuthCode(@RequestBody @Valid AuthCodeDto dto){
        AuthCodeVo vo = authBiz.mailAuthCode(dto);
        return Result.success(vo);
    }

    @PrintlnLog(description = "获取用户随机码")
    @PostMapping("randomCode")
    @CheckToken
    public Result randomCode(@RequestBody @Valid RandomCodeDto dto){
        RandomCodeVo vo = authBiz.randomCode(dto);
        return Result.success(vo);
    }

    @PrintlnLog(description = "获取用户信息")
    @PostMapping("userInfoByCode")
    @RequiredSign
    public Result userInfoByCode(@RequestBody @Valid UserInfoByCodeDto dto){
        UserInfoByCodeVo vo = authBiz.userInfoByCode(dto);
        return Result.success(vo);
    }
}
